<?php

namespace app\store\controller;
use library\tools\Express;
use library\Controller;
use think\Db;

/**
 * 渠道数据
 * Class GoodsCate
 * @package app\store\controller
 */
class Exchange extends Controller
{
    /**
     * 绑定数据表
     * @var string
     */
    protected $table_DB_Platform_Account_qpplatformdb = 'db_platform_qpplatformdb';   /*平台配置库*/
    protected $user_gift_record = 'user_gift_record';                                 /* 平台兑换记录表 */
    protected function Db_connect_user_gift_record()
    {
        $user_data_info = Db::connect($this->table_DB_Platform_Account_qpplatformdb)->table($this->user_gift_record);
        return $user_data_info;
    }
    /**
     * 实物兑换查询
     * @auth true
     * @menu true
     */
    public function index()
    {
        $request = input('request.');
        $this->title = '实物兑换查询';
        $start_time = date('Y-m-d', time() - 2 * 24 * 3600) . ' - ' . date('Y-m-d', time()+24*3600);
        $list =$this->Db_connect_user_gift_record()
            ->where($this->structure_where())
            ->order('InsertTime desc')
            ->paginate(10,false,['query'=>$request]);
        foreach ($list as $k => $v) {
            $user_list[$k] = $v;
        }
        $this->assign('start_time',$start_time);
        $pages = $list->render();
        $this->assign('list',$list);
        $this->assign('pages', $pages);
        $this->fetch();
    }
    protected function structure_where()
    {
        $search_time = $this->request->param('search_time');
        $where = [];
        if (!empty($search_time)) {
            $list = explode(' - ', $search_time);
            $begin = $list[0];
            $after = $list[1];
            $where[] = ['InsertTime', 'between', [$begin, $after]];
        } else {
            $begin = date('Y-m-d', time() - 7 * 24 * 3600);
            $after = date('Y-m-d', time() + 24 * 3600);
            $where[] = ['InsertTime', 'between', [$begin, $after]];
        }
        return $where;
    }




}
